package com.swsc.solarverse.model.base;

import com.swsc.solarverse.common.model.BaseVO;
import com.swsc.solarverse.common.util.BizAssert;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;

/**
 * @Author chencl
 * @Date 2022/6/22 16:38
 * @Version 1.0
 * @Description BaseQueryVO
 */
//@io.swagger.annotations.ApiModel
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
@lombok.Data
public class BaseQueryReqVO extends BaseVO {
//    @io.swagger.annotations.ApiModelProperty(value = "上级组织编号")
    private Integer organPno;
//    @io.swagger.annotations.ApiModelProperty(value = "用户编号")
    private Long userNo;
//    @io.swagger.annotations.ApiModelProperty(value = "组织机构编号In")
    private Collection<Integer> organNoIn;

    private Integer userOrganNo;
    private Integer userTenantNo;


//    @io.swagger.annotations.ApiModelProperty(value = "操作人员类型", hidden = true)
    private String operatorType;

//    @io.swagger.annotations.ApiModelProperty(value = "电站类型", hidden = true)
    private Collection<String> stationTypeIn;

    private Byte offline;
    public void validOrganNo(){
        BizAssert.isFalse(null == getOrganNo(), "请指定电站编号");
    }

    public BaseQueryReqVO(Integer tenantNo, Integer organNo, Long userNo, Collection<Integer> organNoIn){
        super(tenantNo, organNo);
        this.organNoIn = organNoIn;
        this.userNo = userNo;
    }

    public Integer getOrganPno() {
        if(null != getTenantNo() && null != this.organPno && getTenantNo().equals(this.organPno)){
            this.organPno = null;
        }
        return organPno;
    }

    public void parseOrganPno(){
        if(null != getOrganNo() && null == getOrganPno()){
            String organNoStr = getOrganNo().toString();
            if(organNoStr.length() <= 6){
                setOrganPno(getOrganNo());
                if(CollectionUtils.isNotEmpty(getOrganNoIn()) && getOrganNoIn().size() == 1 && getOrganNoIn().contains(getOrganNo())){
                    getOrganNoIn().clear();
                }
                setOrganNo(null);
            }
        }
    }
}
